{% extends "double.html" %}

{% block title %}{{ page_title }}{% endblock %}
{% block styles %}
    <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}styles/privatemsg.css">
{% endblock %}
{% block scripts %}
    <script type="text/javascript">
        $(document).ready(function(){
            var sectionheight = $('section').height();
            $('aside').height(sectionheight);
        })
        $(document).ready(function(){
            var origin = window.location.origin;
            $('.msgdetail').click(function(){
                var readerUrl = $(this).attr('data-readurl');
                var reqUrl = origin + readerUrl;
                $.ajax({
                    type:"GET",
                    dataType:"html",
                    jsonp:"callback",
                    url:reqUrl,
                    success:function(data){
                        document.write(data)
                    },
                    error:function(){
                        console.log('ajax 错误');
                    }
                })
            })
        })        
    </script>
{% endblock %}

{% block main %}    
    
	<div class="privatemsglist">
        <h3>收件箱</h3>
        <div class="message">
        {% if messages %}
            <ul class="messages">
                {% for message in messages %}
                    <li>{{ message }}</li>
                {% endfor %}
            </ul>   
            {% endif %}
        </div>
        <ul>
            {% if pms %}
                {% for pm in pms %}
                    <li>
                        <div class="avatar50">
                            <img src="{{ MEDIA_URL }}avatar/50/{{ pm.sender.profile.avatar }}">
                        </div>
                        <div class="profile">
                            <strong>来自:<a href="{% url mblog_user_index pm.sender.username %}">@{{ pm.sender.username }}</a></strong>
                        </div>
                        {% if pm.isreder == 0 %}
                        <div class="unreader">
                            <a href="{% url mblog_privatemsg_reader user.username pm.id %}">未读</a>
                        </div>
                        {% else %}
                        <div class="reader">
                            已读
                        </div>  
                        {% endif %}
                        <div class="privatemsgshort">
                            <div class="precontent">{{ pm.privatemsg|striptags|slice:'140' }}</div>
                            <em>{{ pm.addtime_format_admin }}</em>
                            <div class="clear"></div>
                        </div>
                        <div class="operating">
                            <a class="msgdetail" href="javascript:;" data-readurl="{% url mblog_privatemsg_reader user.username pm.id %}">详细</a>
                            <a href="{% url mblog_privatemsg_del user.username pm.id %}">删除</a>
                        </div>
                        <div class="clear"></div>
                    </li>
                {% endfor %}
            {% endif %}
        </ul>
    </div> 
{% include 'include/paginator.html' %}
{% endblock %}
{% block aside %}
    <div class="privateinfo">
        <a href="{% url mblog_receiverslist user.username %}">收件箱</a>
        <a href="{% url mblog_senderslist user.username %}">发件箱</a>
        <a href="">最近联系</a>
    </div>
{% endblock%}


